using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace NorthwindDAO
{
	public class Customercustomerdemo : Entity
	{
		private String _CustomerID;
		private String _CustomerTypeID;
	
		///Default constructor
		public Customercustomerdemo ()
		{
		
		}

        /// <summary>
        /// Constructor for joins. 
		/// Available PARENT tables to join with:
		///    - Customerdemographics
		///    - Customers
        /// </summary>
        public Customercustomerdemo(bool Flat, params Entity[] entities)
            : this()
		{
			foreach(Entity entity in entities)
			{
				string[] entityParts = entity.GetType().ToString().Split('.');
				string entityName = entityParts[entityParts.Length - 1];
				PropertyInfo pf = GetType().GetProperty((entityName));
				if (pf != null)
				{
					pf.SetValue(this,new EntityCollection(entity), null);
				}
                entityName = entityName + "_"; ;
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
			}
			SetFlat(Flat);
		}
        public Customercustomerdemo(params Entity[] entities)
            : this(true, entities)
		{
		}
	
		[IsNotNullable]
		[IsPK]
		[MaxLength(5)]
		public String Customerid
		{
			get
			{
				return _CustomerID;
			}
			set
			{
				_CustomerID = value;
			}
		}
		[IsNotNullable]
		[IsPK]
		[MaxLength(10)]
		public String Customertypeid
		{
			get
			{
				return _CustomerTypeID;
			}
			set
			{
				_CustomerTypeID = value;
			}
		}
        #region Customerdemographics 
        private EntityCollection _Customerdemographics;
        [NotInTable]
        [TypeContained(typeof(Customerdemographics),"Customerdemographics")]
        public EntityCollection Customerdemographics
        {
            get
            {
                return _Customerdemographics;
            }

            set
            {
                _Customerdemographics = value;
            }
        }
        private Customerdemographics _Customerdemographics_;
        [NotInTable]
        public Customerdemographics Customerdemographics_
        {
            get
            {
                return _Customerdemographics_;
            }

            set
            {
                _Customerdemographics_ = value;
            }
        }
        #endregion
        #region Customers 
        private EntityCollection _Customers;
        [NotInTable]
        [TypeContained(typeof(Customers),"Customers")]
        public EntityCollection Customers
        {
            get
            {
                return _Customers;
            }

            set
            {
                _Customers = value;
            }
        }
        private Customers _Customers_;
        [NotInTable]
        public Customers Customers_
        {
            get
            {
                return _Customers_;
            }

            set
            {
                _Customers_ = value;
            }
        }
        #endregion
        public override DBJoin GetJoin(string tableName)
        {
	        if (string.Compare(tableName, "Customerdemographics", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
				left.Add(tableName + ".Customertypeid");
				right.Add(GetType().Name + ".Customertypeid");
				return new DBJoin(left, right, JoinTypeEnumeration.INNER);
			}
	        if (string.Compare(tableName, "Customers", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
				left.Add(tableName + ".Customerid");
				right.Add(GetType().Name + ".Customerid");
				return new DBJoin(left, right, JoinTypeEnumeration.INNER);
			}
			return null;
		}
	}
}


